home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Mac OS Development Toolkit / Automation Essentials 2.3.0 / Host Automation Folder / SPEC Libs / Print.Lib < prev    next >
Encoding:
Text File  |  1998-03-19  |  16.6 KB  |  501 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:        Print.Lib
  5. #
  6. #    Contains:    xxx put contents here xxx
  7. #
  8. #    Written by:    KTA, KL, ML, GS et al
  9. #
  10. #    Copyright:    © 1993-1996 by Apple Computer, Inc., all rights reserved.
  11. #
  12. # ****************************************************************************
  13. #            C h a n g e        H i s t o r y (most recent first):
  14. # ****************************************************************************
  15. #
  16. #        Vers      Date        Author        Description
  17. #        ----    --------    ------    ---------------------------------------------
  18. #    <1.0.14>      5/1/96    MDF        PageSetup() - Modified to include hierarchical         selection
  19. #                                    of Page Setup menu item.
  20. #    1.0.13+>      5/1/96    MDF        PageSetup() - Modified to include hierarchical selection of Page
  21. #                                    Setup menu item.
  22. #    <1.0.13>      1/2/96    ML        add TCS for printing
  23. #    1.0.12+>      1/2/96    ML        add TCS for printing
  24. #    <1.0.12>     11/8/95    ML        fixed Printer() header
  25. #    1.0.11+>     11/8/95    ML        fixed Printer() header
  26. #    <1.0.11>      5/8/95    ML        change PrintTest to gPrinttest
  27. #    1.0.10+>      5/8/95    ML        change PrintTest to gPrinttest
  28. #    <1.0.10>     2/14/95    KTA        PageSetup() - Added BooleanFlag to FindWindow() call
  29. #     <1.0.9>     12/2/94    ML        Added Exception Handling support
  30. #     <1.0.8>     4/29/94    KTA        PageSetup() - Fail TCS if dialog didn't appear.
  31. #     <1.0.7>     3/15/94    KTA        PageSetup() - Check to make sure Page Setup dialog appeared.
  32. #    <1.0.5+>    11/19/93    NAGA        modify TCS format
  33. #     <1.0.5>     8/25/93    KTA        Added support for parity checking the TCS stack.
  34. #     <1.0.4>     7/19/93    KTA        Updates for FindWindow() to handle descriptors.
  35. #     <1.0.3>     7/14/93    KTA        International Support: See Printer(), and PageSetUp().
  36. #        <1+>     5/21/93    NAGA        Adding header and porting old files to follow new standards
  37. #
  38. # ****************************************************************************
  39. #
  40.  
  41. ########################################################################
  42. #                            External libraries 
  43. #=======================================================================
  44. Libraries "Output.Lib","TCS.Lib","UserInterface.Lib", "ExceptionHandling.Lib";
  45.  
  46. #########################################################################
  47. #                            PageSetup.lib
  48. #========================================================================
  49. # Description:    This file contains Task to test the page setup dialog.
  50. #                Currently only TestPageSetup() should be called. The
  51. #                other Tasks are support for this Task.
  52. #
  53. #            Tasks:
  54. #                TestPageSetup(checkBoxTest,paperSizeTest,pageSizeTest,orientationTest,printTest)
  55. #                TestCheckBoxList(checkBoxList)
  56. #                PaperSize()
  57. #                PageSize()
  58. #                ToggleOrientation()
  59. #                PrintSample()
  60. #
  61. #     Copyright Apple Computer, Inc. 1985-1990
  62. #    All rights reserved
  63. #========================================================================
  64. #     ECH        11/29/90        Created
  65. #########################################################################
  66.  
  67.  
  68. #########################################################################
  69. #    TestPageSetup(checkBoxTest,paperSizeTest,pageSizeTest,orientationTest,printTest)
  70. #========================================================================
  71. # Author:        EH
  72. # Description:    Tests the standard page setup.  All permutations of 
  73. #                checkboxes, paper radio buttons, scale controls, and 
  74. #                orientation icons are selected.  
  75. # Parameters:    checkBoxTest -    0 = do not test checkboxes
  76. #                                    1 = test check boxes
  77. #                paperSizeTest -    0 = do not test paper sizes
  78. #                                1 = test paper sizes
  79. #                pageSizeTest -    0 = do not test page sizes
  80. #                                1 = test page sizes
  81. #                orientationTest -    0 = do not test orientation
  82. #                                    1 = test orientation
  83. #                printTest -    0 = do not print after each combination
  84. #                            1 = perform print test after each combination
  85. # Returns:        0 = Error occured in testing
  86. #                1 = Successful test
  87. # Examples:        TestPageSetup(1,0,0,1,0);
  88. # Assumptions:    A Page Setup dialog is up.
  89. #========================================================================
  90. # History:
  91. # ML    11/29/94    Added Exception Handling support
  92. #########################################################################
  93. TASK TestPageSetup(checkBoxTest := 1,paperSizeTest := 1,pageSizeTest := 1,orientationTest := 1,printTest := 0)
  94. begin
  95.     (*    ** Sample Printer Entry **
  96.     Parameters := {    Printer Name,
  97.                     list of check box names,
  98.                     list of paper size radio button names,
  99.                     list of page size radio button names, 
  100.                         or 0 if size is a text entry field
  101.                         or if page size is changed by up and down controls, a list
  102.                            with first element = # of possible values and the next
  103.                            two = location of controls,
  104.                     location of portrait orientation control relative to the window,
  105.                     location of lanscape orientation control relative to the window
  106.                   };
  107.     *)
  108.     PrinterList := {
  109.             {    'LaserWriter Page Setup',
  110.                 { 'Font Substitution?','Text Smoothing?','Graphics Smoothing?','Faster Bitmap Printing?' },
  111.                 { 'US Letter','US Legal','A4 Letter','B5 Letter','' },
  112.                 0,                                # Text field
  113.                 { 80,135 },
  114.                 { 115,135 } 
  115.             },
  116.             {    'Personal LaserWriter LS',
  117.                 { 'Precision Bitmap Alignment' },
  118.                 { 'US Letter','US Legal','A4 Letter','B5 Letter','No. 10 Envelope' },
  119.                 { '100%','75%','50%' },
  120.                 { 40,120 },
  121.                 { 80,120 }
  122.             },
  123.             {    'Personal LaserWriter SC',
  124.                 { 'Exact Bit Images (Shrink 4%)','Text Smoothing' },
  125.                 { 'US Letter','US Legal','A4 Letter','B5 Letter','No. 10 Envelope' },
  126.                 { '100%','75%','50%' },
  127.                 { 30,115 },
  128.                 { 70,115 }
  129.             },
  130.             {    'Tabasco',
  131.                 { },
  132.                 { 'US Letter','US Legal','A4 Letter','Envelope (#10)' },
  133.                 { 5,{ 317,93 },{ 317,83 } },    # up and down controls
  134.                 { 120,100 },
  135.                 { 160,100 }
  136.             }
  137.     };
  138.     
  139.     ### Check to see if the page setup dialog is for a known printer
  140.     for i := 1 to card printerList
  141.         if (_matchBoolean ([staticText t:printerList[i][1]]!))
  142.         begin
  143.             printerName := printerList[i][1];
  144.             global printerParameters := printerList[i];
  145.             global testCheckBoxes := checkBoxTest;
  146.             global testPaperSize := paperSizeTest;
  147.             global testPageSize := pageSizeTest;
  148.             global testOrientation := orientationTest;
  149.             global testPrint := printTest;
  150.             LogStr("====================================================================");
  151.             LogStr("Testing PageSetup for {printerName}");
  152.             ### First excercise the checkboxes, then paper size radio buttons, page 
  153.             ### size controls, and orientation controls.
  154.             TestCheckBoxList(printerList[i][2]);
  155.              
  156.             ### excercise help
  157.             if (_matchBoolean ([button t:'Help']!))
  158.             begin
  159.                 LogStr("Testing Help");
  160.                 if (SelectButton('Help'))
  161.                 begin
  162.                     wait(2);
  163.                     SelectButton('OK');
  164.                 end;
  165.             end;
  166.             
  167.             ### successful test
  168.             return(1);
  169.         end;
  170.  
  171.     ### No match on any of the known printers
  172.     LogStr("*** Unknown Printer type ***");
  173.     return(0);
  174. end;
  175.     
  176.  
  177. #########################################################################
  178. #                    TestCheckBoxList(printerParameters)
  179. #========================================================================
  180. # Author:        EH
  181. # Description:    Selects all possible combinations of check boxes by
  182. #                recursive calls to itself.  After each combination, it
  183. #                calls PaperSize() which will result in all possible
  184. #                combinations of check boxes, paper sizes, page sizes, and
  185. #                orientations.
  186. # Parameters:    checkBoxList -    A list of check box names
  187. # Returns:        Nothing
  188. #========================================================================
  189. # History:
  190. #
  191. #########################################################################
  192. TASK TestCheckBoxList(checkBoxList)
  193. begin
  194.     if (global testCheckBoxes)
  195.     begin
  196.         if (card checkBoxList = 0)
  197.         begin
  198.             PaperSize();
  199.             return(0);
  200.         end;
  201.         else
  202.             for a := 1 to 2
  203.             begin
  204.                 TestCheckBoxList(remove(1,checkBoxList));
  205.                 SelectCheckBox(checkBoxList[1]);
  206.             end;
  207.     end;
  208.     else
  209.         PaperSize();
  210. end;
  211.  
  212.  
  213. #########################################################################
  214. #                            PaperSize()
  215. #========================================================================
  216. # Author:        EH
  217. # Description:    Selects all the paper size radio buttons.  After selecting
  218. #                each button, it calls PageSize() to go through all possible
  219. #                page sizes and then orientations.  This exercises all
  220. #                possible combinations of paper size, page size, and 
  221. #                orientation.
  222. # Parameters:    None
  223. # Returns:        Nothing
  224. #========================================================================
  225. # History:
  226. #
  227. #########################################################################
  228. TASK PaperSize()
  229. begin
  230.     global printerParameters;
  231.     
  232.     if (global testPaperSize)
  233.     begin
  234.         for a := 1 to card printerParameters[3]
  235.         begin
  236.             SelectRadioButton(printerParameters[3][a]);
  237.             PageSize();
  238.         end;
  239.     end;
  240.     else
  241.         PageSize();
  242. end;
  243.  
  244.  
  245. #########################################################################
  246. #                                PageSize()
  247. #========================================================================
  248. # Author:        EH
  249. # Description:    Selects the paper size in one of either three ways: Typing
  250. #                values in a text edit field, selecting an up and down 
  251. #                control, or by selecting radio buttons.  In between each
  252. #                page size, this function calls ToggleOrientation.
  253. # Parameters:    None
  254. # Returns:        Nothing
  255. #========================================================================
  256. # History:
  257. # ML    11/29/94    Added Exception Handling support
  258. #########################################################################
  259. TASK PageSize()
  260. begin
  261.     global printerParameters;
  262.     
  263.     if (global testPageSize)
  264.     begin
  265.         if (printerParameters[4] = 0)
  266.         begin
  267.             ### Text entry field so type in values 100,80,60,40,20
  268.             for b := 100 to 20 step -20
  269.             begin
  270.                 # erase old value
  271.                 _type ({ backspacekey,backspacekey,backspacekey });
  272.                 # type in new value
  273.                 TypeStr("{b}");
  274.                 # Change orientation
  275.                 ToggleOrientation();
  276.             end;
  277.         end;
  278.         else if (TypeOf(printerParameters[4][1]) = 'integer')
  279.         begin
  280.             ### Up and down arrow controls to select size
  281.             for b := 1 to printerParameters[4][1]
  282.             begin
  283.                 # Select down control
  284.                 temp := global gDisableAllLogging;
  285.                 global gDisableAllLogging := 1;
  286.                 MoveRelativeToWindow(printerParameters[4][2][1],printerParameters[4][2][2],1,2);
  287.                 global gDisableAllLogging := temp;
  288.                 LogStr("Pressed scale down control");
  289.                 ToggleOrientation();
  290.             end;
  291.             for b := 1 to printerParameters[4][1]
  292.             begin
  293.                 # reset control by selecting up
  294.                 temp := global gDisableAllLogging;
  295.                 global gDisableAllLogging := 1;
  296.                 MoveRelativeToWindow(printerParameters[4][3][1],printerParameters[4][3][2],1,2);
  297.                 global gDisableAllLogging := temp;
  298.                 LogStr("Pressed scale up control");
  299.             end;
  300.         end;
  301.         else
  302.             ### There are radio buttons to select size
  303.             for b := 1 to card printerParameters[4]
  304.             begin
  305.                 SelectRadioButton(printerParameters[4][b]);
  306.                 ToggleOrientation();
  307.             end;
  308.     end;
  309.     else
  310.         ToggleOrientation();
  311. end;
  312.  
  313.  
  314. #########################################################################
  315. #                    ToggleOrientation()
  316. #========================================================================
  317. # Author:        EH
  318. # Description:    Toggles the portrait and landscape icons.
  319. # Parameters:    None
  320. # Returns:        Nothing
  321. # Examples:        ToggleOrientation();
  322. #========================================================================
  323. # History:
  324. #
  325. #########################################################################
  326. TASK ToggleOrientation()
  327. begin
  328.     global printerParameters;
  329.     
  330.     if (global testOrientation)
  331.     begin
  332.         temp := global gDisableAllLogging;
  333.         global gDisableAllLogging := 1;
  334.         MoveRelativeToWindow(printerParameters[5][1],printerParameters[5][2],1,2);
  335.         global gDisableAllLogging := 0;
  336.         LogStr("Pressed Portrait control");
  337.         PrintSample();
  338.         global gDisableAllLogging := 1;
  339.         MoveRelativeToWindow(printerParameters[6][1],printerParameters[6][2],1,2);
  340.         global gDisableAllLogging := temp;
  341.         LogStr("Pressed Landscape control");
  342.         PrintSample();
  343.     end;
  344. end;
  345.  
  346.  
  347. #########################################################################
  348. #                    PrintSample()
  349. #========================================================================
  350. # Author:        EH
  351. # Description:    Prints the current document and then reopens the pagesetup
  352. #                dialog.
  353. # Parameters:    None
  354. # Returns:        Nothing
  355. # Examples:        PrintSample();
  356. #========================================================================
  357. # History:
  358. # ML    11/29/94    Added Exception Handling support
  359. #########################################################################
  360. TASK PrintSample()
  361. begin
  362.     if (global testPrint)
  363.     begin
  364.         SelectButton('OK');                            # close page setup dialog
  365.         
  366.         ### Remember front window
  367.         frontWindow := _match ([window o:1]!,1);
  368.         
  369.         if (SelectMenuItem('Print','File'))
  370.         begin
  371.             SpecialKey(returnKey,"Return Key");        # close print dialog
  372.             LogStr("Printing Document");
  373.         end;
  374.         
  375.         ### Wait for frontWind to become the front window again
  376.         while not (_matchBoolean ([window o:1 t:frontWindow.t]!));
  377.         
  378.         if not (SelectMenuItem('Page Setup','File'))
  379.         begin
  380.             LogStr("#### ERROR: Could not open page setup. Exiting script");
  381.             exit;
  382.         end;
  383.     end;
  384. end;
  385.  
  386. #########################################################################
  387. #                    PrintAlert() 
  388. #========================================================================
  389. # Author:            EH
  390. # Description:        Logs the Static text from an alert dialog.
  391. # Parameters:        none
  392. # Return Values:    none
  393. # Examples:            PrintAlert();
  394. #========================================================================
  395. # History:
  396. # ML    11/29/94    Added Exception Handling support
  397. #########################################################################
  398. TASK PrintAlert()
  399. begin
  400.     messages := _collect ([staticText w:[window o:1]]);
  401.     if (card messages > 0)
  402.     begin
  403.         first := messages[1].t;
  404.         LogStr("!@#$% ALERT: {first}");
  405.     end;
  406.     if (card messages > 1)
  407.     begin
  408.         second := messages[2].t;
  409.         LogStr("!@#$% ALERT: {second}");
  410.     end;
  411. end;
  412.  
  413. ########################################################################
  414. #                        PageSetup( WhichDevice )
  415. #=======================================================================
  416. # Author:             KTA
  417. # Description:        For PageSetup routines
  418. # Parameters:        WhichDevice - device
  419. #                    PagSetupMI - pageSetup menuItem descriptor
  420. # Returns:            None
  421. #=======================================================================
  422. # History:
  423. # KTA    7/8/93    International support: Pass in PageSetup menuItem descriptor
  424. # KTA    7/19/93    changed descriptor so it is not embedded in a list
  425. # KTA    8/24/93    TCS stack parity check
  426. # KTA    3/15/94    Check to make sure Page Setup dialog appeared
  427. # KTA    4/29/94    Fail TCS if dialog didn't appear
  428. # ML    11/29/94    Added Exception Handling support
  429. # KTA    2/14/95        Added BooleanFlag to FindWindow() call
  430. # MDF    04/24/96    Added Hierarchical menu support for selecting Page Setup.
  431. ########################################################################
  432. TASK PageSetup(WhichDevice := "LaserWriter", PagSetupMI := {"Page Setup", "File"}) 
  433. begin
  434.     if ( WhichDevice = "LaserWriter")
  435.     begin
  436.         FrontWindow := _Match([window o:1]!,1);
  437.         failStr := '';
  438.         TCSStart({ 1, global kTCSetPageSetup },"Select 'Page Setup'");
  439.         if(card(PagSetupMI) = 3)
  440.             returnVal := SelectMenuItem(PagSetupMI[1], PagSetupMI[2], PagSetupMI[3]);
  441.         else
  442.             returnVal := SelectMenuItem(PagSetupMI[1], PagSetupMI[2]);
  443.         if(returnVal)
  444.         begin
  445.             wait(3);
  446.             currentWindow := _Match([window o:1]!,1);
  447.             if not (FrontWindow = currentWindow)
  448.                 returnVal := 1;
  449.             else
  450.             begin
  451.                 failStr := "No dialogs appeared after selecting the 'Page Setup' menu item";
  452.                 returnVal := 0;
  453.             end;
  454.         end;
  455.         
  456.         TCSEnd({ 1, global kTCSetPageSetup }, returnVal, failStr);    #To select Page SetUp…
  457.         wait(1);
  458.         if(returnVal)
  459.         begin
  460.             PageSetupDesc:= _match([window o:1]!,1);
  461.             TCSStart({ 2, global kTCSetPageSetup },"Dismiss the Page Setup Dialog");
  462.             SpecialKey(returnKey, 'Return Key');    #To Select the Default-'OK'
  463.             wait(1);
  464.             if not (FindWindow(PageSetupDesc, true))
  465.                 TCSEnd({ 2, global kTCSetPageSetup },1);
  466.             else
  467.                 TCSEnd({ 2, global kTCSetPageSetup },0);
  468.         end;
  469.     end;
  470. end; # PageSetup()
  471.  
  472. ########################################################################
  473. #                        Printer()
  474. #=======================================================================
  475. # Author:             KTA
  476. # Description:        For Print routines
  477. # Parameters:        PrintMI - menuItem descriptor
  478. # Returns:            None
  479. #=======================================================================
  480. # History:
  481. # KTA    7/8/93    International Support: Pass in MenuItem descriptor
  482. # ML    1/2/96    add tcs calls
  483. ########################################################################
  484. TASK Printer(PrintMI := {"Print", "File"}) 
  485. begin
  486.     if     (global gPrintTest)
  487.     begin
  488.         TCSStart({ 1, global kTCSetPrinting },"Select 'Print' Menuitem");
  489.         SelectMenuItem(PrintMI[1], PrintMI[2]);        #To select Print
  490.         wait(2);
  491.         PrintDialogDesc:= _match([window o:1]!,1);
  492.         if (global gPrinterHook)
  493.             call (gPrinterHook);
  494.         SpecialKey(returnKey, 'Return Key');    #To Select the Default-'OK'
  495.         if not (FindWindow(PrintDialogDesc, true))
  496.             TCSEnd({ 1, global kTCSetPrinting },1);
  497.         else
  498.             TCSEnd({ 1, global kTCSetPrinting },0);
  499.     end;
  500. end; # Printer()
  501.